package com.ruoyi.project.wxapi.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.meal.domain.MealMilk;
import com.ruoyi.project.meal.domain.MealMilkList;
import com.ruoyi.project.meal.domain.MealServiceObjects;
import com.ruoyi.project.meal.domain.MealServiceObjectsList;
import com.ruoyi.project.meal.service.IMealMilkListService;
import com.ruoyi.project.meal.service.IMealMilkService;
import com.ruoyi.project.meal.service.IMealServiceObjectsListService;
import com.ruoyi.project.meal.service.IMealServiceObjectsService;
import com.ruoyi.project.wxapi.model.dto.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("牛奶报餐")
@RestController
@RequestMapping("/wxapi/milk")
public class WxapiMilkController {
    @Autowired
    IMealMilkListService milkListService;
    @Autowired
    IMealMilkService milkService;

    @RequestMapping("/lists")
    public Result lists(String className,String reportDate,String phase,String campus) {
        MealMilk mealMilk=new MealMilk();
        mealMilk.setClassName(className);
        mealMilk.setPhase(phase);
        mealMilk.setCampus(campus);
        if(!StringUtils.isEmpty(reportDate)){
            mealMilk.setReportDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD,reportDate));
        }
        return Result.success(milkService.selectMealMilkList(mealMilk));
    }

    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    @PostMapping("/insert")
    public Result insert(@RequestBody List<MealMilk> list) {
        if(list!=null&& list.size()>0){
            for (MealMilk m:list ) {
                milkService.insertMealMilk(m);
            }
        }

        return Result.success("新增成功");
    }

    @PostMapping("/update")
    public Result update(@RequestBody List<MealMilk> list) {
        if(list!=null&& list.size()>0){
            for (MealMilk m:list ) {
                milkService.updateMealMilk(m);
            }
        }
        return Result.success("更新成功");
    }


}
